#!/bin/bash

# Create folders to store figures and tables if not found

mkdir -p plots
mkdir -p tables

# Install package dependencies
dependencies=(
    "Rmisc"
    "tidyverse"
    "readxl"
    "stargazer"
    "kableExtra"
    "sandwich"
    "broom"
    "dotwhisker"
    "jtools"
    "scales"
    "xtable"
    "DeclareDesign"
    "DesignLibrary"
    "future.apply"
)

for pkg in "${dependencies[@]}"; do
    /usr/bin/env Rscript -e "if(require('$pkg') == FALSE) install.packages('$pkg', repos='https://cloud.r-project.org')"
done

# Execute all the R scripts in the code folder
find ./code -name "*.R" -exec /usr/bin/env Rscript {} \;
